// Not-tabbar/my_upload/my_upload.js
const appInstance = getApp();
import { fetchDetailByCreat } from '../../Service/CategoryService'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mineLoad:[],
  },

  goToUpload()  {
    wx.navigateTo({
      url: '/Not-tabbar/hc-upload/hc-upload',
    })
  },

  //获取自己上传的药膳
  async fetchMedifoodDetails() {
    try {
      // 获取当前用户的created_by
      const user = await wx.BaaS.auth.getCurrentUser();
      const createdBy = user.get('created_by');

      const medifoodDetails = await fetchDetailByCreat(createdBy);
      this.setData({
        mineLoad: medifoodDetails
      });
    } catch (error) {
      console.error('Failed to fetch medifood details:', error);
    }
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.fetchMedifoodDetails();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (!appInstance.checkTokenValidity()) {
      // Token 已过期或不存在，已重新登录
      console.log('Token expired, re-login in progress');
    } else {
      console.log('Token is valid');
    }
    this.fetchMedifoodDetails();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})